const bcrypt = require('bcrypt');
const db = require('../db');

async function createAdmin(username, password, nickname) {
    try {
        // 生成密码哈希
        const salt = await bcrypt.genSalt(10);
        const hashedPassword = await bcrypt.hash(password, salt);
        
        // 插入管理员记录
        const [result] = await db.promise().execute(
            'INSERT INTO admin (username, password, nickname) VALUES (?, ?, ?)',
            [username, hashedPassword, nickname]
        );
        
        console.log('管理员创建成功:', {
            id: result.insertId,
            username,
            nickname
        });
        
    } catch (error) {
        console.error('创建管理员失败:', error);
    } finally {
        process.exit();
    }
}

// 创建默认管理员
createAdmin('admin', '123456', '管理员'); 